<include file="Public/min-header" /> <!--引入 js css img 文件-->
<script src="__PUBLIC__/js/jquery-1.10.2.min.js"></script>
<script src="__STATIC__/js/slider.js"></script>
<script src="__PUBLIC__/js/global.js"></script>
<script src="__PUBLIC__/js/pc_common.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
</head>
<body>
    <!--导航  start //-->
    <include file="Public/header" />  <!--引入头部导航  //-->
    <!--导航 End  //-->
    <div id="main">
        <!--右边菜单-->
        <include file="User/menu" />
        <!--右边菜单End-->
        <div class="mainfr-box">
            <div class="place">
                <span>位置：</span>
                <ul class="placeul">
                    <li><a href="__MODULE__/User/index.html">首页➤</a></li>
                    <li><a href="__MODULE__/User/firstlevel.html">验证邮箱</a></li>
                </ul>
                <ul class="placeula">
                    <li><a href="javascript:location.reload()"><span class="placea"></span>刷新</a></li>
                    <li><a href="javascript:history.go(-1)"><span class="placea"></span>返回上一页</a></li>
                </ul>
            </div>
            <div class="clr"></div>
            <div class="main">

                <form method="post" onsubmit="return check_form();" />
                <table width="100%" border="0" class="Register-table">
                    <tr>
                        <th scope="row">原邮箱：</th>
                        <td colspan="3">
                            <input type="text" class="dfinput" id="old_email" name="old_email" placeholder="没有请留空">
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">新邮箱：</th>
                        <td colspan="3">
                            <input type="text" class="dfinput" id="new_email" name="email">
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">验证码：</th>
                        <td colspan="3">
                            <input type="text" id="new_code" maxlength="4" style="width:100px;" class="dfinput" name="code" />
                            <input type="button" intervaltime="120" class="scbtn1" value="获取验证码 " id="btnemailAuthCode2" onClick="sendCode(this,'new_email')">
                        </td>
                    </tr>
                </table>
                <div class="button-box"><input class="button-style" type="submit" id="but" value="确认修改" ></div>
                </form>
            </div>
        </div>
        <!--foot-->
        <div class="clr"></div>
        <!--footer start //-->
        <include file="Public/footer" />  <!--引入底部 //-->
        <!--footer  end //-->
</body>
</html>
<script>
    // 表单提交验证
    function check_form()
    {
        var old_email = $('#old_email').val();
        var new_email = $('#new_email').val();
        //原邮箱不为空的情况下 验证格式
        if(old_email != ''){
            if(!checkEmail(old_email)){
                layer.alert('原邮箱格式错误', {icon: 2});//alert('原邮箱格式错误');
                return false;
            }
        }
        if(!checkEmail(new_email)){
            layer.alert('新邮箱格式错误', {icon: 2});//alert('新邮箱格式错误');
            return false;
        }

        if($.trim($('#new_code').val()) == '')
        {
            layer.alert('验证码不能为空', {icon: 2});//alert('验证码不能为空');
            return false;
        }
        return true;
    }

    function sendCode(obj,input_id){
        var id = $(obj).attr('id');
        var input = $('#'+input_id).val();
        var old_email = $('#old_email').val();
        //原邮箱不为空的情况下 验证格式
        if(old_email != ''){
            if(!checkEmail(old_email)){
                layer.alert('原邮箱格式错误', {icon: 2});//alert('原邮箱格式错误');
                return false;
            }
        }
        if(!checkEmail(input)){
            layer.alert('邮箱格式错误', {icon: 2});//alert('邮箱格式错误');
            return false;
        }
        if(input_id == 'old_email')
            var url = "/index.php?m=Home&c=User&a=send_validate_code&step=1&type=email&send="+input;
        if(input_id == 'new_email')
            var url = "/index.php?m=Home&c=User&a=send_validate_code&step=2&type=email&send="+input;
        //发送验证码
        $.ajax({
            type : "GET",
            url  : url,
            dataType : 'json',
            error: function(request) {
                layer.alert('服务器繁忙, 请联系管理员!', {icon: 2});//alert("服务器繁忙, 请联系管理员!");
                return;
            },
            success: function(v) {
                if(res.status == 1){
                    jsInnerTimeout(id);
                }else{
                    layer.alert(res.msg,{icon: 2});//alert('发送失败');
                }
            }
        });
    }

    //倒计时函数
    function jsInnerTimeout(id)
    {
        var codeObj=$("#"+id);
        var intAs=parseInt(codeObj.attr("IntervalTime"));

        intAs--;
        codeObj.attr("disabled","disabled");
        if(intAs<=-1)
        {
            codeObj.removeAttr("disabled");
            codeObj.attr("IntervalTime",120);
            codeObj.val("获取验证码");
            return true;
        }
        codeObj.val(intAs+'s后再次获取');
        codeObj.attr("IntervalTime",intAs);
        setTimeout("jsInnerTimeout('"+id+"')",1000);
    }

</script>